using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CanBeSeen : MonoBehaviour
{
	public float m_DistanceToSee = 5.0f;
	public float m_FractionOfScreenAngle = 0.6f;

	public float m_AngleFromViewerToMe;

	public bool m_IsSeen = false;
	private Vector3 m_DudePos;
	private Vector3 m_MyPos;
	private Vector3 m_DirFromDudeToMe;

	void Start()
	{
	}

	void Saw()
	{
	}

	void Lost()
	{
	}

	void Update()
	{
		m_DudePos = ThePlayer.m_GameObj.transform.position;
		m_MyPos   = transform.position;

		if ( Vector3.Distance( m_DudePos, m_MyPos ) <= m_DistanceToSee )
		{
			m_DirFromDudeToMe = (m_DudePos - m_MyPos); 
			m_DirFromDudeToMe.Normalize();

			m_AngleFromViewerToMe = 180f - Mathf.Acos( Vector3.Dot( ThePlayer.m_Camera.transform.forward, m_DirFromDudeToMe ) ) * Mathf.Rad2Deg;
			if ( m_AngleFromViewerToMe <= (ThePlayer.m_Camera.fieldOfView * m_FractionOfScreenAngle) )
			{
				m_IsSeen = true;
				Saw();
			}
			else
			{
				m_IsSeen = false;
				Lost();
			}
		}
	}

	void OnDrawGizmos()
	{
		Gizmos.DrawRay( m_MyPos, m_DirFromDudeToMe );
	}

	void OnDrawGizmosSelected() 
	{
		Gizmos.color = Color.white;
		Gizmos.DrawWireSphere( transform.position, m_DistanceToSee );
	}
}

